<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Layui</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="/addons/hc_answer/template/plugins/layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="/addons/hc_answer/template/css/global.css" media="all">
		<link rel="stylesheet" type="text/css" href="/addons/hc_answer/template/plugins/font-awesome/css/font-awesome.css">
		<link rel="stylesheet" href="/addons/hc_answer/template/css/table.css" />
		<link rel="shortcut icon" href="./resource/images/favicon.ico" />
		<link href="./resource/css/bootstrap.min.css?v=20170915" rel="stylesheet">
		<link href="./resource/css/common.css?v=20170915" rel="stylesheet">
		<script type="text/javascript">
			if(navigator.appName == 'Microsoft Internet Explorer'){
				if(navigator.userAgent.indexOf("MSIE 5.0")>0 || navigator.userAgent.indexOf("MSIE 6.0")>0 || navigator.userAgent.indexOf("MSIE 7.0")>0) {
					alert('您使用的 IE 浏览器版本过低, 推荐使用 Chrome 浏览器或 IE8 及以上版本浏览器.');
				}
			}
			window.sysinfo = {
				{if !empty($_W['uniacid'])}'uniacid': '{$_W['uniacid']}',{/if}
				{if !empty($_W['acid'])}'acid': '{$_W['acid']}',{/if}
				{if !empty($_W['openid'])}'openid': '{$_W['openid']}',{/if}
				{if !empty($_W['uid'])}'uid': '{$_W['uid']}',{/if}
				'isfounder': {if !empty($_W['isfounder'])}1{else}0{/if},
				'family': '{IMS_FAMILY}',
				'siteroot': '{$_W['siteroot']}',
				'siteurl': '{$_W['siteurl']}',
				'attachurl': '{$_W['attachurl']}',
				'attachurl_local': '{$_W['attachurl_local']}',
				'attachurl_remote': '{$_W['attachurl_remote']}',
				'module' : {'url' : '{if defined('MODULE_URL')}{MODULE_URL}{/if}', 'name' : '{if defined('IN_MODULE')}{IN_MODULE}{/if}'},
				'cookie' : {'pre': '{$_W['config']['cookie']['pre']}'},
				'account' : {php echo json_encode($_W['account'])},
				'server' : {'php' : '{php echo phpversion()}'},
			};
		</script>
		<script>var require = { urlArgs: 'v=20170915' };</script>
		<script type="text/javascript" src="./resource/js/lib/jquery-1.11.1.min.js"></script>
		<script type="text/javascript" src="./resource/js/lib/bootstrap.min.js"></script>
		<script type="text/javascript" src="./resource/js/app/util.js?v=20170915"></script>
		<script type="text/javascript" src="./resource/js/app/common.min.js?v=20170915"></script>
		<script type="text/javascript" src="./resource/js/require.js?v=20170915"></script>
		<style type="text/css">
			body{
				background-color:#fff;
				min-width: 100%;
			}
			.layui-form-label{
				width: 120px
			}
			.input-group .form-control{
				width:430px;
			}
			legend{
				width:14%;
			}
		</style>
	</head>

	<body >
		<div style="margin: 15px;">
			<fieldset class="layui-elem-field">
				<legend>排位赛设置</legend>
			
				<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
					<div class="layui-tab-content" >
						<!-- 基础设置 开始-->
						<form class="layui-form" action="" id="form">
							<div class="layui-form-item">
							    <label class="layui-form-label">关卡编号</label>
							    <div class="layui-input-inline">
							      <input type="number" name="dan_id" value="{$info['dan_id']}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger">
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">段位名称</label>
							    <div class="layui-input-inline">
							      <input type="text" name="name" value="{$info['name']}"  lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger">
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">答题设置</label>
							    <div class="layui-input-block">
							      <input type="radio" name="robot" value="1" title="机器人" {if $info['robot']=='1'}checked="checked"{/if}{if empty($info['robot'])}checked="checked"{/if}>
							      <input type="radio" name="robot" value="2" title="异步匹配" {if $info['robot']=='2'}checked="checked"{/if}>
							    </div>
							    <span style="color:red">建议刚开始运营的童鞋，使用机器人答题，后期答题数量多了，更改成异步匹配</span>
							</div>
							<div class="layui-form-item">
							      <label class="layui-form-label">赛季分组</label>
							      <div class="layui-input-inline">
							        <select name="season">
							          {loop $season $item}
							          <option value="{$item['no']}" {if $item['no']==$info['season']}selected="selected"{/if}>{$item['name']}</option>
							          {/loop}
							        </select>
							    </div>
							</div>
							<div class="layui-form-item box" id="selprop">
							    <label class="layui-form-label">设置题目</label>
							    <div class="layui-input-inline">
									<a href="javascript:;" class="layui-btn layui-btn-small" data-id="{$info['id']}" id="addlibrary">
										<i class="layui-icon"></i> 选择题目
									</a>
									<input type="hidden" name="remark" id="remark" value="{$info['quesids']}" >
								</div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">段位图片</label>
							    <div class="layui-input-inline" style="width:150px">
									{php echo tpl_form_field_image('thumbs',$info['thumb']);}
									<span style="color:red">建议尺寸936*308</span>
								</div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">消耗金币</label>
							    <div class="layui-input-inline">
							      <input type="number" name="use_gold" value="{$info['use_gold']}"  lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger">
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">奖励金币</label>
							    <div class="layui-input-inline">
							      <input type="number" name="win_gold" value="{$info['win_gold']}"  lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger">
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">关卡数量</label>
							    <div class="layui-input-inline">
							      <input type="number" name="win_star" value="{$info['win_star']}"  lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger">
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">段位头像框</label>
							    <div class="layui-input-inline" style="width:150px">
									{php echo tpl_form_field_image('border',$info['border']);}
								</div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">设置赛季奖励</label>
							    <div class="layui-input-block">
									<a href="javascript:;" class="layui-btn layui-btn-small" id="addprop">
										<i class="layui-icon"></i> 选择物品
									</a>
									<input type="hidden" name="reward" id="reward" value="{$info['reward']}">
									<div style="border: 1px dashed #d6bdbd;width: 50%; font-size: 20px;margin-left: 9px;">
										<img src="{media $prop['thumb']}" style="width: 70px"/>
										{$prop['name']}
									</div>
								</div>
							</div>
							
							<div class="layui-form-item">
							    <label class="layui-form-label">赛季奖励数量</label>
							    <div class="layui-input-inline">
							      <input type="number" name="rewardnum" value="{$info['rewardnum']}"  lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger">
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">赢取经验</label>
							    <div class="layui-input-inline">
							      <input type="number" name="winexp" value="{$info['winexp']}"  lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger">
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">失败经验</label>
							    <div class="layui-input-inline">
							      <input type="number" name="failexp" value="{$info['failexp']}"  lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger">
							    </div>
							</div>
							
							<input type="hidden" name="id" value="{$info['id']}" >
							<div class="layui-form-item">
							    <div class="layui-input-block">
							      <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="rankadd" style="pointer-events: auto;">立即提交</button>
							      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
							    </div>
							</div>

							</form>
							
						<!-- 题目设置 结束-->
					</div>
				</div>	
			</fieldset>
		</div>

		<script type="text/javascript" src="/addons/hc_answer/template/plugins//layui/layui.js"></script>
		<script>
			layui.use(['form','upload','laypage','layer'], function() {
				var $ = layui.jquery,
				upload = layui.upload,
				form = layui.form();
				form.render();
				form.on('submit(rankadd)', function(data) {
					$.ajax({
			            url:"{php echo $this->createWebUrl('rankdo');php}",
			            data:$('#form').serialize(),
			            type:"post",
			            dataType:"json",
			            success:function(data){
			            	if(data.code=='1'){
			                	layer.alert(data.msg, {icon: 6},function(index){
			                		var index = parent.layer.getFrameIndex(window.name);
			                		parent.layer.close(index)
			                	});
								
			            	}else{
			                	layer.alert(data.msg, {icon: 5});
			            	}
			            },
			            error:function(data){
			                layer.alert('请稍后重试', {icon: 5});
			            }
			        });
					return false;
				});
  
				 //普通图片上传
				layui.upload({
					elem: '#thumb',
					url: '{php echo $this->createWebUrl("Uploadimg");php}',
					success: function(res){
						if(res.code==1){
							$('#show').attr('src', res.path);
							$('#thumbs').val(res.path);
						}
					}
				});  

				$("#addprop").click(function(){
					layer.open({
					  type: 2,
					  area: ['900px', '650px'],
					  fixed: false, //不固定
					  maxmin: true,
					  content: './index.php?c=site&a=entry&do=selectprop&m=hc_answer',
					  btn: ['确定','关闭'],
                      yes: function(index){
					  		var res = window["layui-layer-iframe" + index].callbackdata();
							$("#reward").val(res);

	                        //最后关闭弹出层
	                        layer.close(index);
	                    },
	                    cancel: function(){
	                        //右上角关闭回调
	                    }
					});
				});

				$("#addlibrary").click(function(){
					var id = $(this).attr('data-id');
					layer.open({
					  type: 2,
					  area: ['80%', '800px'],
					  fixed: false, //不固定
					  maxmin: true,
					  content: './index.php?c=site&a=entry&do=selectlib&m=hc_answer&id='+id,
					  btn: ['继续添加','一键重置','提交并关闭'],
					  yes: function(index){
					  		var res = window["layui-layer-iframe" + index].callbackdata();
					  		$("#remark").val(res)
					  		$.ajax({
					            url:"{php echo $this->createWebUrl('rankdo',array('act'=>'ques'));php}",
					            data:{id:id,remark:res},
					            type:"post",
					            dataType:"json",
					            success:function(data){
					                layer.alert(data.msg, {icon: 6});
					            },
					            error:function(data){
					                layer.alert('请稍后重试', {icon: 5});
					            }
					        });
					        return false;
	                    },btn2:function(index){
							$("iframe").contents().find( "tr" ).css( "background-color", "" )
							$("iframe").contents().find( "input[type='checkbox']").attr("checked",false);
							$("iframe").contents().find( "#questions").val('');
					  		$("#remark").val('')
					  		$.ajax({
					            url:"{php echo $this->createWebUrl('rankdo',array('act'=>'ques'));php}",
					            data:{id:id,remark:''},
					            type:"post",
					            dataType:"json",
					            success:function(data){
					            	layer.alert(data.msg, {icon: 6});
					            },
					            error:function(data){
					                layer.alert('请稍后重试', {icon: 5});
					            }
					        });
					        return false;
	                    },btn3:function(index){
	                    	var res = window["layui-layer-iframe" + index].callbackdata();
					  		$("#remark").val(res)
					  		$.ajax({
					            url:"{php echo $this->createWebUrl('rankdo',array('act'=>'ques'));php}",
					            data:{id:id,remark:res},
					            type:"post",
					            dataType:"json",
					            success:function(data){
					            	layer.alert(data.msg, {icon: 6});
					            },
					            error:function(data){
					                layer.alert('请稍后重试', {icon: 5});
					            }
					        });

	                        layer.close(index);
	                    },cancel: function(){
	                        //右上角关闭回调
	                    }
					});
				});
				function array_intersection(a, b) { // 交集
				    var result = [];
				    for(var i = 0; i < b.length; i ++) {
				        var temp = b[i];
				        for(var j = 0; j < a.length; j ++) {
				            if(temp === a[j]) {
				                result.push(temp);
				                break;
				            }
				        }
				    }
				    return array_remove_repeat(result);
				}
				function array_difference(a, b) { // 差集 a - b
				    //clone = a
				    var clone = a.slice(0);
				    for(var i = 0; i < b.length; i ++) {
				        var temp = b[i];
				        for(var j = 0; j < clone.length; j ++) {
				            if(temp === clone[j]) {
				                //remove clone[j]
				                clone.splice(j,1);
				            }
				        }
				    }
				    return array_remove_repeat(clone);
				}
				function array_remove_repeat(a) { // 去重
				    var r = [];
				    for(var i = 0; i < a.length; i ++) {
				        var flag = true;
				        var temp = a[i];
				        for(var j = 0; j < r.length; j ++) {
				            if(temp === r[j]) {
				                flag = false;
				                break;
				            }
				        }
				        if(flag) {
				            r.push(temp);
				        }
				    }
				    return r;
				} 
			});
		</script>

	</body>

</html>